<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<h2><fmt:message key="form.RequestDetails" /></h2>

<div class="messages"><jsp:include page="/messages.jsp" /></div>

<c:if test = "${requestBean.requestStatus.id != 6}">
  <div class="links">
    <a class="control" href="leadexecutorui?_action=requestEditForm&request_id=${requestBean.id}">
      <fmt:message key="Command.edit"/> 
    </a>
  </div>
</c:if>

<table>
  <tr>
    <td>
    <table class="form">
      <tr>
        <td class="label"><fmt:message key="request.id" /></td>
        <td><c:out value="${requestBean.id}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.status" /></td>
        <td><c:out value="${requestBean.requestStatus.status}" /><br>
        
        <!-- start status manage block --> 
        <c:if
          test="${requestBean.requestStatus.id != 6}">
          [
          <c:choose>
            <c:when test="${requestBean.requestStatus.id != 5}">
              <a class="control"
                href="leadexecutorui?_action=setRequestInactive&request_id=${requestBean.id}">
              <fmt:message key="Command.requestInactive" /> </a>
            </c:when>
            <c:otherwise>
              <a class="control"
                href="leadexecutorui?_action=setRequestActive&request_id=${requestBean.id}">
              <fmt:message key="Command.requestActive" /> </a>
            </c:otherwise>
          </c:choose>
          <a class="control"
            href="leadexecutorui?_action=setRequestCompleated&request_id=${requestBean.id}">
          <fmt:message key="Command.requestCompleated" /> </a>
          ]
        </c:if>                             
        
        <!-- end status manage block -->
        
        </td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.priority" /></td>
        <td><c:out value="${requestBean.priorityBean.value}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.regNumber" /></td>
        <td><c:out value="${requestBean.regNumber}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.organization" /></td>
        <td><c:out value="${requestBean.organization.fullTitle}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.department" /></td>
        <td><c:out value="${requestBean.department.name}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.client" /></td>
        <td><c:out value="${requestBean.client.lastName}" />&nbsp;
        <c:out value="${requestBean.client.firstName}" />&nbsp; <c:out
          value="${requestBean.client.middleName}" /><br>
        [<a
          href='mailto:<c:out value = "${requestBean.client.email1}"/>'>
        <c:out value="${requestBean.client.email1}" /> </a>]</td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="client.tel1" /></td>
        <td><c:out value="${requestBean.client.tel1}" default='---' /><br>
        <c:out value="${requestBean.client.tel2}" /><br>
        <c:out value="${requestBean.client.tel3}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.room" /></td>
        <td><c:out value="${requestBean.room}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.text" /></td>
        <td class="textField"><c:out
          value="${requestBean.clientText}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.dispatcherText" /></td>
        <td class="textField"><c:out
          value="${requestBean.dispatcherText}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.group" /></td>
        <td><c:out value="${requestBean.group.name}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.requestType" /></td>
        <td><c:out value="${requestBean.requestType.type}" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.regDate" /></td>
        <td><fmt:formatDate value="${requestBean.registrationDate}"
          pattern="dd.MM.yyyy HH:mm" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.approxEndDate" /></td>
        <td><fmt:formatDate value="${requestBean.approxEndDate}"
          pattern="dd.MM.yyyy" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.realEndDate" /></td>
        <td><fmt:formatDate value="${requestBean.realEndDate}"
          pattern="dd.MM.yyyy HH:mm" /></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.leadExecutor" /></td>
        <td><c:out value="${requestBean.leadExecutor.lastName}" />&nbsp;
        <c:out value="${requestBean.leadExecutor.firstName}" />&nbsp; <c:out
          value="${requestBean.leadExecutor.middleName}" /><br>
        [<a
          href='mailto:<c:out value = "${requestBean.leadExecutor.email}"/>'>
        <c:out value="${requestBean.leadExecutor.email}" /> </a>]</td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="Command.executorsList" /></td>
        <td>
        
          <c:if test = "${requestBean.requestStatus.id != 6}">
          <p>
            <a class = "control" href = "leadexecutorui?_action=taskForm&request_id=${requestBean.id}">
              <fmt:message key = "Command.addTask"/>
            </a> 
          </p> 
          </c:if>  
        
        <!-- executors table -->

        <table class="regular">
          <thead>
            <tr>
              <th>N</th>
              <th><fmt:message key="task.executor"/></th>
              <th><fmt:message key="task.text"/></th>
              <th><fmt:message key="task.startdate"/></th>
              <th><fmt:message key="task.approxenddate"/></th>
              <th><fmt:message key="task.enddate"/></th>
              <th><fmt:message key="task.status"/></th>
              <th><fmt:message key="task.operations"/></th>
            </tr>
          </thead>

          <tbody>
            <c:choose>
              <c:when test="${fn:length(tasksList) != 0}">
                <c:forEach var="task" items="${tasksList}">
                  <tr>
                    <td><c:out value="${task.id}" /></td>
                    <td><c:out value="${task.executor.lastName}" />&nbsp;
                    <c:out value="${task.executor.firstName}" /></td>

                    <td class="textField"><c:out
                      value="${fn:substring(task.text, 0, 200)}" /></td>
                    <td><fmt:formatDate value="${task.startDate}"
                      pattern="dd.MM.yyyy" /></td>
                    <td><fmt:formatDate
                      value="${task.approxEndDate}" pattern="dd.MM.yyyy" /></td>
                    <td><fmt:formatDate value="${task.endDate}"
                      pattern="dd.MM.yyyy" /></td>
                    <td><c:out value="${task.status.status}" /></td>
                    <td>
                    <ul class="navbar2">
                      <li><a
                        href="leadexecutorui?_action=taskDetails&request_id=${requestBean.id}&task_id=${task.id}">
                      <fmt:message key="Command.details" /> </a></li>
                    </ul>
                    </td>
                  </tr>
                </c:forEach>
              </c:when>
              <c:otherwise>
                <tr>
                  <td colspan="8">
                  <center><fmt:message key="emptyList" /></center>
                  </td>
                </tr>
              </c:otherwise>
            </c:choose>
          </tbody>
        </table>
        
        <!-- end executors table -->
        
        <c:if test = "${requestBean.requestStatus.id != 6}">
          <p>
            <a class = "control" href = "leadexecutorui?_action=taskForm&request_id=${requestBean.id}">
              <fmt:message key = "Command.addTask"/>
            </a> 
          </p>  
        </c:if></td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.report" /></td>
        <td>
          <c:if test = "${requestBean.requestStatus.id != 6}">
            <a class="control" href="leadexecutorui?_action=reportForm&request_id=${requestBean.id}">
              <fmt:message key="Command.writeReport" /> 
            </a>
          </c:if>  
        <p><c:out value="${requestBean.leadExecutorReport}" /></p>
        </td>
      </tr>

      <tr>
        <td class="label"><fmt:message key="request.comment" /></td>
        <td><c:out value="${requestBean.comment}" /></td>
      </tr>
    </table>
    </td>
    <!-- end left column -->

    <td valign="top"><jsp:include page="/dayRequests.jsp" /></td>
  </tr>
</table>
